<!doctype html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />

    <!-- Include jQuery Mobile stylesheets -->
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">

    <!-- Include the jQuery library -->
    <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

    <!-- Include the jQuery Mobile library -->
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>

    <style type="text/css">
        BODY {
            font-family: arial, sans-serif;
        }
        .imglist {
            display: none;
        }
        #cv {
            position: absolute;
            top: 0px;
            left: 0px;
        }
        #footer {
            background-color: rgba(0, 0, 0, 0);
            border: none;
            float: left;
        }
        .score {
            background-color: rgba(211, 215, 207, 0.5);
            text-align: center;
            border-radius: 2em;
        }
        .pi_count {
            color: rgb(78, 154, 6);
        }
        .atmp_count {
            color: rgb(206, 92, 0);
        }
        .timer_count {
            color: rgb(92, 53, 102);
        }
        .btn {
            text-align: center;
        }
        .inline {
            display: inline;
        }
        .hide {
            display: none;
        }
        #submit {
            padding: 5px;
            padding-left: 25px;
            padding-right: 25px;
            margin-right: 10px;
            opacity: 0.5;
        }
    </style>
    <script type="text/javascript" src="kaleidoscope.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            $(".hide").parent().hide();

            var rotate = true,
                shape = 'triangle',
                img = "cross",
                bg = '#000000',
                ks,
                stats = {
                    pi_count: 0,
                    atmp_count: 0,
                    timer_count: 0
                },
                curStats = {
                    pi_count: 0,
                    atmp_count: 0,
                    timer_count: 0
                };

			$("#footer a").click(function(){
				var tm = curStats.timer_count + stats.timer_count;
				$("#rsh").html(tm);
				$("#rph").html((curStats.pi_count + stats.timer_count) * 360);
				$("#rah").html(curStats.atmp_count + stats.atmp_count);
				var high = "您的时间碎片率为<span style=\"color:red\">高<"+"/span>，请注意管理自己的时间！";
				var med = "您的时间碎片率为<span style=\"color:green\">中<"+"/span>，您可以更多思考人生理想！";
				var low = "您的时间碎片率为<span style=\"color:blue\">低<"+"/span>，请注意适当放松自己！";
				var rep = low;
				if(tm > 30){
					rep = med;
				} 
				if( tm > 180){
					rep = high;
				}
				$("#segrate").html(rep);
			});

            $("#btn-set-done").click(function() {
                if (ks) {
                    ks.destroy();
                }
                img = $("select")[0].value;
                rotate = $("#rotate")[0].checked;
                shape = $("#triangle")[0].checked ? "triangle" : "square";
                updateScreen();
            });
            updateScreen(countTime);


            function countTime() {
                stats.timer_count += 1;
                $('.timer_count').html((stats.timer_count));
                $('input[name="timer"]').val(stats.timer_count);
                setTimeout(countTime, 1000);
            }

            function updateScreen(cb) {
                var imgList = $('#img-' + img).html().replace(/^\s+|\s+$/g, '').split(/\s+/g);

                if ('amon' === img) {
                    bg = '#eeeeee';
                } else {
                    bg = '#000000';
                }

                stats.pi_count += curStats.pi_count;
                stats.atmp_count += curStats.atmp_count;
                stats.timer_count += curStats.timer_count;

                ks = kaleidoscope($("#cv")[0].getContext('2d'), imgList, bg, rotate, shape,cb);
                ks.addStatsListener(function() {
                    curStats.pi_count = Math.floor(ks.getStats().angle / 360);
                    curStats.atmp_count = ks.getStats().attempts;
                    $('.pi_count').html((stats.pi_count + curStats.pi_count));
                    $('input[name="pi"]').val(stats.pi_count + curStats.pi_count);
                    $('.atmp_count').html((stats.atmp_count + curStats.atmp_count));
                    $('input[name="atmp"]').val(stats.atmp_count + curStats.atmp_count);
                });
            }
        });
    </script>
    <title>微游戏之忆童年万花筒</title>
</head>

<body>
    <div class="imglist" id="img-amon">
        assets/amon1.png assets/amon2.png assets/amon3.png assets/amon4.png assets/amon5.png assets/amon6.png
    </div>
    <div class="imglist" id="img-atoms">
        assets/atom1.png assets/atom2.png assets/atom3.png assets/atom4.png assets/atom5.png
    </div>
    <div class="imglist" id="img-cross">
        assets/b.png assets/c.png assets/g.png assets/m.png assets/o.png assets/p.png assets/r.png assets/y.png
    </div>
    <div class="imglist" id="img-snow">
        assets/snowflake1.png assets/snowflake2.png assets/snowflake3.png assets/snowflake4.png assets/snowflake5.png
    </div>

    <div id="home" data-role="page">
        <div data-role="main" class="ui-content">
            <canvas id="cv">你的浏览器不支持HTML5</canvas>
            <a href="#dialog" class="ui-btn ui-corner-all ui-icon-gear ui-btn-icon-notext" data-transition="fade" style="z-index:0;opacity : 0.75">选择图案</a>
        </div>
        <div id="footer" data-role="footer" data-position="fixed">
            <div>
                <input class="hide" type="text" name="pi" value="0">
            </div>
            <div>
                <input class="hide" type="text" name="atmp" value="0">
            </div>
            <div>
                <input class="hide" type="text" name="timer" value="0">
            </div>
            <div class="inline score">
                <span class="pi_count">0</span>圈
            </div>
            <div class="inline score">
                <br><span class="atmp_count">0</span>次
            </div>
            <div class="inline score">
                <br><span class="timer_count">0</span>秒
            </div>
            <div class="inline " style="float:right">
                <a href="#report" data-rel="popup" class="ui-btn ui-mini" style="opacity:0.5">无聊，玩够了！</a>
            </div>
        </div>
         <div data-role="popup" data-arrow="b" id="report" class="ui-content">
            <a href="#" data-rel="back" class="ui-btn ui-corner-all ui-shadow ui-btn ui-icon-delete ui-btn-icon-notext ui-btn-right">Close</a>
			<p>你用了<span id="rah">0</span>次、<span id="rsh">0</span>秒、旋转了万花筒<span id="rph">0</span>度。</p>
			<p id="segrate">_</p>
            <a href="asddf" data-rel="back" class="ui-btn ui-corner-all ui-shadow">再玩一会儿</a>
        </div>
    </div>


    <div data-role="page" data-dialog="true" id="dialog">
        <div data-role="header">
            <h1>设置</h1>
        </div>
        <div data-role="main" class="ui-content">
            <label for="img">选择图案：</label>
            <select name="img" id="img">
                <option value="cross" selected>
                    绚丽十字
                </option>
                <option value="snow">
                    缤纷雪花
                </option>
                <option value="atoms">
                    运转原子
                </option>
                <option value="amon">
                    多拉A梦
                </option>
            </select>
            <label for="rotate">屏幕旋转：</label>
            <input type="checkbox" data-role="flipswitch" name="rotate" id="rotate" checked>
            <fieldset data-role="controlgroup">
                <legend>选择镜筒形状：</legend>
                <label for="square">方形</label>
                <input type="radio" name="shape" id="square" value="square">
                <label for="triangle">三角形</label>
                <input type="radio" name="shape" id="triangle" value="triangle" checked>
            </fieldset>
            <a id="btn-set-done" href="#home" class="ui-btn ui-shadow" data-transition="fade" data-theme="b">确定</a>
        </div>
    </div>
</body>

</html>
